package com.alex.algorithm.easy;

public class MaxDepthBinaryTree {

    public static void main(String[] args) {
        BinaryTreeNode root = new BinaryTreeNode();

        BinaryTreeNode n1 = new BinaryTreeNode();
        n1.setValue(1);
        root.setLeft(n1);

        BinaryTreeNode n2 = new BinaryTreeNode();
        n2.setValue(2);
        root.setRight(n2);

        BinaryTreeNode n3 = new BinaryTreeNode();
        n3.setValue(3);

        n2.setRight(n3);

        BinaryTreeNode n4 = new BinaryTreeNode();
        n4.setValue(3);
        n3.setRight(n4);



        System.out.println(depth(root));
    }

    private static int depth(BinaryTreeNode root) {
        if (root == null) return 0;
        if (root.getLeft() == null && root.getRight() == null) return 1;
        return 1 + Math.max(depth(root.getLeft()), depth(root.getRight()));
    }
}
